# -*- coding:utf-8 -*-
# time: 2025/7/3 ♡  16:58
# author:张伟
import os
import datetime
from sqlalchemy.pool import NullPool

# 项目根路径
BASE_DIR = os.path.dirname(__file__)

# CSRF秘钥
SECRET_KEY = "DDAKGNDJKLAKGNKJD"

# 数据库配置
DB_HOST = '127.0.0.1'
DB_PORT = 3306
DB_USER = 'root'
DB_PASS = '123456'
DATABASE = 'bbs_vue'

DB_URI = 'mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8'.format(DB_USER, DB_PASS, DB_HOST, DB_PORT, DATABASE)
SQLALCHEMY_DATABASE_URI = DB_URI
SQLALCHEMY_TRACK_MODIFICATIONS = False

# SQLALCHEMY_ENGINE_OPTIONS= {
#    'pool_size': 20,          # 连接池大小（建议 Worker 数量 * 2）
#    'max_overflow': 10,       # 允许超出 pool_size 的临时连接数
#    'pool_timeout': 30,       # 获取连接的超时时间（秒）
#    'pool_recycle': 3600,     # 定期回收连接（防止数据库断开）
#    'pool_pre_ping': True,    # 每次获取连接前检查有效性
#}
SQLALCHEMY_ENGINE_OPTIONS={
        'poolclass':NullPool
 }


# QQ邮箱配置
MAIL_SERVER = 'smtp.qq.com'
MAIL_PORT = 465
MAIL_USE_SSL = True
MAIL_USERNAME = "3479519845@qq.com"
MAIL_PASSWORD = "akcdgxompcbfcgif"
MAIL_DEFAULT_SENDER = "3479519845@qq.com"


# celery配置
BROKER_URL = "redis://:123456@127.0.0.1:6379/0"
RESULT_BACKEND = "redis://:123456@127.0.0.1:6379/0"
TASK_IGNORE_RESULT = True

# flask-Caching 配置
CACHE_TYPE = "RedisCache"
CACHE_REDIS_HOST = "127.0.0.1"
CACHE_REDIS_PORT = 6379
CACHE_REDIS_PASSWORD = "123456"
CACHE_DEFAULT_TIMEOUT = 300

# session.permanent = True 时session过期时间：7天
PERMANENT_SESSION_LIFETIME = 604800

# flask-avatars 配置
AVATARS_SAVE_PATH = os.path.join(BASE_DIR, "media", "avatars")

# 上传图片保存路径
IMAGE_SAVE_PATH = os.path.join(BASE_DIR, "media", "post_image")

# 轮播图图片保存路径
BANNER_IMAGE_SAVE_PATH = os.path.join(BASE_DIR, "media", "banner_image")

# 分页大小
PAGE_SIZE = 10

# JWT过期时间
JWT_ACCESS_TOKEN_EXPIRES = datetime.timedelta(minutes=30)
JWT_REFRESH_TOKEN_EXPIRES = datetime.timedelta(days=7)
